#pragma once

#include <Windows.h>
#include <d3d9.h>      // Main Direct3D header
#include <d3dx9.h>	
#include <string>
#include "Global.h"

class Sprite
{
protected:
	LPDIRECT3DTEXTURE9 texture;

	D3DXVECTOR2 position;
	D3DXVECTOR2 scale;
	D3DXVECTOR2 center;

	float width;
	float height;

public:

	Sprite(void)
	{

	}

	~Sprite(void)
	{
	
	}

	bool LoadSprite(LPDIRECT3DDEVICE9 device, std::wstring filename)
	{
		D3DXCreateTextureFromFile(device, filename.c_str(), &texture);
	
		D3DXIMAGE_INFO imageInfo;
		D3DXGetImageInfoFromFile(filename.c_str(), &imageInfo);

		height = (float)imageInfo.Height;
		width = (float)imageInfo.Width;

		position = D3DXVECTOR2(100.0f,400.0f);
		scale = D3DXVECTOR2(1.0f,1.0f);
		center = D3DXVECTOR2(width / 2, height /2);

		return true;
	}


	void Render(LPD3DXSPRITE SpriteBatch, int alpha)
	{
		D3DXMATRIX Matrix;
		D3DXMatrixTransformation2D(&Matrix, NULL, 0.0F, &scale, NULL, 0, &position);
		// out, scaling centre, scaling rotation, scaling, rotation centre, rotation, translation

		SpriteBatch->SetTransform(&Matrix);
		SpriteBatch->Draw(texture, NULL, NULL, NULL, D3DCOLOR_RGBA(255,255,255,alpha));
	}

	void SetPosition(int x, int y)
	{
		position.x = (float)x;
		position.y = (float)y;
	}

	void SetSize(int newWidth, int newHeight)
	{
		scale.x = (float)newWidth/width;
		scale.y = (float)newHeight/height;
	}


	int GetWidth()
	{
		return (int)width;
	}

	int GetHeight()
	{
		return (int)height;
	}

};